package com.jkl.controller.drTemplateDetail;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.drTemplateDetail.DrTemplateDetail;
import com.jkl.service.drTemplateDetail.inter.DrTemplateDetailServiceInterface;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/jky/drTemplateDetail")
@Slf4j
public class DrTemplateDetailController {

	@Autowired
	private HttpServletRequest request;

	@Autowired
	private DrTemplateDetailServiceInterface DrTemplateDetailServiceInterface;
	
	@PostMapping("/selectDetailById")
	public BaseResponseDTO selectDetailById(@RequestBody DrTemplateDetail drTemplateDetail) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		
		List<DrTemplateDetail> drTemplateDetailList = DrTemplateDetailServiceInterface.selectDetailById(drTemplateDetail);
		JSONObject returnJson = new JSONObject();
		JSONArray drTemplateDetailArray = (JSONArray) JSONArray.toJSON(drTemplateDetailList);
		returnJson.put("drTemplateDetailList", drTemplateDetailArray);
		returnData.setReturnData(returnJson);
		return returnData;

	} 
	
	@PostMapping("/saveDetailById")
	public BaseResponseDTO saveDetailById(@RequestBody DrTemplateDetail drTemplateDetail) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		drTemplateDetail.setStatus("1");
		int drTemplateDetailInt = DrTemplateDetailServiceInterface.saveDetailById(drTemplateDetail);
		if(drTemplateDetailInt!=0) {
			returnData.setResultMessage("添加成功");
		}else { 
			returnData.setResultMessage("添加失败");
		}
		
		return returnData;

	} 
	@PostMapping("/deleteDetailById")
	public BaseResponseDTO deleteDetailById(@RequestBody DrTemplateDetail drTemplateDetail) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		drTemplateDetail.setStatus("启用");
		int drTemplateDetailInt = DrTemplateDetailServiceInterface.deleteDetailById(drTemplateDetail);
		if(drTemplateDetailInt!=0) {
			returnData.setResultMessage("删除成功");
			System.out.println("删除成功");
		}else { 
			returnData.setResultMessage("删除失败");
		}
		
		return returnData;

	} 
	
	
}
